local skel = fk.CreateSkill {
  name = "lb__kansha",
  tags = { Skill.Spirited },
}

Fk:loadTranslationTable {
  ["lb__kansha"] = "堪杀",
  --[[
  [":lb__kansha"] = "<a href='#SpiritedSkillDesc'><b>昂扬技</b></a>，" ..
      "当一名角色使用<font color='red'>♦</font>牌指定其他角色为唯一目标时，你可将之改为【火攻】，此流程中目标与使用者的展示与弃置的操作均由你观看其手牌并执行。" ..
      "若你有<a href=':lb__shengbian'><font color='red'>〖升变〗</font></a>花色，<font color='red'>♦</font>改为〖升变〗花色。" ..
      "<a href='#SpiritedSkillDesc'>激昂</a>：你四次移去〖升变〗花色。激昂前，〖逐火〗失效。",
  --]]
  --原描述
  [":lb__kansha"] = "<a href='#SpiritedSkillDesc'><b>昂扬技</b></a>，" ..
      "当一名角色使用<font color='red'>♦</font>牌指定其他角色为唯一目标时，你可将之改为【火攻】，此流程中目标与使用者的展示与弃置的操作均由你观看其手牌并执行。" ..
      "若<a href=':lb__shengbian'><font color='red'>〖擢英〗</font></a>未用尽，<font color='red'>♦</font>改为〖擢英〗花色。" ..
      --"<a href='#SpiritedSkillDesc'>激昂</a>：四张〖升变〗花色牌被使用。激昂前，〖逐火〗失效。",
      "<a href='#SpiritedSkillDesc'>激昂</a>：四张牌因〖擢英〗额外结算。激昂前，〖逐火〗失效。",

  ["@lb__kansha"] = "堪杀",
  ["#lb__kansha"] = "堪杀：你可以将 %src 对 %dest 使用的 %arg 改为【火攻】",

  ["$lb__kansha1"] = "汝等，满盘皆输！",
  ["$lb__kansha2"] = "我已来，我已见，我已征服。",
}

Fk:addPoxiMethod { --火攻
  name = "lb__kansha_fire_attack_skill",
  card_filter = function(to_select, selected, data, extra_data)
    if #selected == 0 and extra_data.suit then
      if Fk:getCardById(to_select).suit == extra_data.suit then
        local owner = Fk:currentRoom():getCardOwner(to_select)
        return not (owner and owner:prohibitDiscard(to_select))
      end
    end
  end,
  feasible = function(selected, data, extra_data)
    return #selected == 1
  end,
  prompt = function(data, extra_data)
    return extra_data.prompt
  end,
}

skel:addEffect(fk.TargetSpecifying, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player:getMark("@lb__kansha") == 0
        and data.to ~= target and data:isOnlyTarget(data.to)
        and data.card.name ~= "fire_attack" and not data.cancelled
        and
        (data.card.suit == Card.Diamond or table.contains(player:getTableMark("@lb__shengbian_suit"), data.card:getSuitString(true)))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      {
        skill_name = skel.name,
        prompt = "#lb__kansha:" .. target.id .. ":" .. data.to.id .. ":" .. data.card:toLogString(),
      })
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@lb__kansha", 4)
    -- 改变使用的卡牌
    ---@param name? string
    ---@param suit? Suit
    ---@param number? integer
    ---@param skill_name? string
    ---@param skill? Skill
    local function changeCard(name, suit, number, skill_name, skill)
      if data.card.name == name and data.card.suit == suit and data.card.number == number then
        return
      end
      name = name or data.card.name
      suit = suit or data.card.suit
      number = number or data.card.number
      local card = Fk:cloneCard(name, suit, number)
      for k, v in pairs(data.card) do
        if card[k] == nil then
          card[k] = v
        end
      end
      if data.card:isRuleVirtual() then
        card.subcards = data.card.subcards
      else
        card.id = data.card.id
      end
      card.virt_id = data.card.virt_id
      card.skillNames = data.card.skillNames
      if skill_name then
        table.insertIfNeed(card.skillNames, skill_name)
      end
      local room = RoomInstance
      if room then
        if card.virt_id ~= 0 then
          room:sendCardVirtName({ card.virt_id }, name, true)
        else
          room:sendCardVirtName(Card:getIdList(card), name)
        end
      end
      card.skill = skill
      data.card = card
    end
    changeCard("fire_attack", nil, nil, skel.name, Fk.skills["lb__kansha_fire_attack_skill"])
    data.extra_data = data.extra_data or {}
    data.extra_data.lb__kansha_fire_attack = player.id
  end,
})
--[[
skel:addEffect(fk.CardUsing, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name, true) and player:getMark("@lb__kansha") > 0
    and table.contains(player:getTableMark("@lb__shengbian_suit"), data.card:getSuitString(true))
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "@lb__kansha")
  end,
})
--]]
skel:addLoseEffect(function(self, player)
  player.room:setPlayerMark(player, "@lb__kansha", 0)
end)

skel:addEffect("invalidity", {
  invalidity_func = function(self, from, skill)
    if from:getMark("@lb__kansha") > 0 and string.find(skill.name, "lb__zhuhuo") then
      return true
    end
  end,
})

return skel